package com.my.chapter15;


import net.mindview.util.CountingGenerator;
import net.mindview.util.Generator;

import java.util.*;

public class practice13 {
    public static void main(String[] args) {
        List<StoryCharacter> storyCharacterList = OverloadedFill.fill(
                new ArrayList<StoryCharacter>(), new CharacterGenerator(), 3);
        for(StoryCharacter c : storyCharacterList)
            System.out.print(c + ", ");
        System.out.println("");

        Queue<Integer> iQueue = OverloadedFill.fill(
                (Queue<Integer>)new LinkedList<Integer>(),
                new Fibonacci(), 12);
        for(int i : iQueue)
            System.out.print(i + " ");
        System.out.println("");

        LinkedList<Character> cLList = OverloadedFill.fill(
                new LinkedList<Character>(),
                new CountingGenerator.Character(), 12);
        for(char ch : cLList)
            System.out.print(ch);
        System.out.println("");

        Set<Boolean> bSet = OverloadedFill.fill(
                new HashSet<Boolean>(),
                new CountingGenerator.Boolean(), 10);
        for(Boolean b : bSet)
            System.out.println(b);
        System.out.println("");
    }
}

class OverloadedFill{
    public static <T> List<T>
    fill(List<T> list, Generator<T> gen, int n) {
        for(int i = 0; i < n; i++)
            list.add(gen.next());
        return list;
    }

    public static <T> Queue<T>
    fill(Queue<T> queue, Generator<T> gen, int n) {
        for(int i = 0; i < n; i++)
            queue.add(gen.next());
        return queue;
    }

    public static <T> Set<T>
    fill(Set<T> set, Generator<T> gen, int n) {
        for(int i = 0; i < n; i++)
            set.add(gen.next());
        return set;
    }

    public static <T> LinkedList<T>
    fill(LinkedList<T> llist, Generator<T> gen, int n) {
        for(int i = 0; i < n; i++)
            llist.add(gen.next());
        return llist;
    }
}
